<?php
namespace Duobao\Controller;


class RechargeController extends ControllerBase{
    /**
     * 充值controller
     */

    /**
     * 默认
     */
    public function index()
    {
        echo "<!--hi , i'm from " . MODULE_NAME . "~" . APP_STATUS, "-->";
    }

    /**
     * 创建充值订单,转发数据到order controller
     */
    public function createRechargeOrder(){
        $ret = array();
        $ret['status'] = 200;
        $ret['msg'] = '';
        $ret['data'] = array();

        try{
            $type = I('post.type');
            #$money = intval(I('post.money'));
            $money = I('post.money');
            $uid = $this->getUid(I('get.token'));
            if(!empty($type)){
                if(!empty($money)){
                    if(is_numeric($uid) && $money>0){
                        $result = R('Order/createOrder',array($uid,$type,$money));#调用订单控制器，生成充值订单
                        if($result){
                            $ret['data'] = $result;
                        }else{
                            $ret['status'] = 403;
                            $ret['msg'] = $result;#返回false
                        }
                    }else{
                        $ret['status'] = 403;
                        $ret['msg'] = $uid;
                    }
                }else{
                    $ret['status'] = 403;
                    $ret['message'] = '金额不能为空';
                }
            }else{
                $ret['status'] = 403;
                $ret['message'] = '订单类型不能为空';
            }
        }catch (\Exception $e){
            $ret['status'] = $e->getCode();
            $ret['msg'] = $e->getMessage();
        }

        return $this->response($ret);
    }

        /*end of Recharge controller*/
}